package states;

import gui.OpCom;
import monitor.StateVariableMonitor;
import regulators.BallAndBeamRegul;
import regulators.BeamRegul;
import se.lth.control.realtime.DigitalIn;
import se.lth.control.realtime.DigitalOut;

public class ReleaseBall extends StateClass implements State {
	long excecutionTime = System.currentTimeMillis();


	public ReleaseBall(DigitalIn initialPosSensor, DigitalOut digitalSolenoid, BeamRegul beam,
			BallAndBeamRegul ballAndBeam, OpCom op, StateVariableMonitor stateVariableMonitor) {
		super(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor);

	}

	@Override
	public void initialExcecution() {
		op.displayStep("ReleaseBall");
		try{
			digitalSolenoid.set(false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void excecute() {
	}

	@Override
	public boolean stateOfExcecution() {
		if ( beam.controllerStatMonitor.hasPosDer() && !beam.controllerStatMonitor.hasReached(-4) ) {
			return true;
		}
		return false;
	}



	@Override
	public void nextState() {
		setCurrentState(new BallAndBeam(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor));

	}

	@Override
	public void suspend() {
		beam.shutDown();
	}

	@Override
	public void resume() {
		beam.restart();
		this.initialExcecution();
	}
}